package com.epay;


public class CreaterUtil
{
  public static String trimAll(String str)
  {
    return str.replaceAll(" ", "");
  }

  public static String replaceAll(String str, String from, String to)
  {
    while (str.indexOf(from) > 0) {
      str = str.replace(from, to);
    }
    return str;
  }

 /* public static String getFieldType(String inputtype)
  {
    if (inputtype.equals("java.lang.Integer"))
      return "int";
    if (inputtype.equals("java.lang.Short"))
      return "short";
    if (inputtype.equals("java.lang.Long"))
      return "long";
    if (inputtype.equals("java.lang.String"))
      return "String";
    if (inputtype.equals("java.lang.Boolean"))
      return "boolean";
    if (inputtype.equals("java.lang.Float"))
      return "float";
    if (inputtype.equals("java.lang.Double"))
      return "double";
    if (inputtype.equals("java.lang.Character"))
      return "char";
    if (inputtype.equals("java.lang.Byte")) {
      return "byte";
    }
    return inputtype;
  }*/
  
  public static String getJavaForDbType(String inputtype){
	  String returnStr="";
	  switch(inputtype){
	  	case "INT":
	  		returnStr="INTEGER";
	  		break;
		case "TEXT":
	  		returnStr="VARCHAR";
	  		break;
		case "LONGTEXT":
	  		returnStr="VARCHAR";
	  		break;
		case "LONGBLOB":
	  		returnStr="VARCHAR";
	  		break;
		case "DATETIME":
			returnStr="TIMESTAMP";
	  		break;
		case "JSON":
			returnStr="VARCHAR";
	  		break;
	  	default:
	  		returnStr=inputtype;
	  		break;
	  }
	  return returnStr;
  }
  
  /**
   * 根据数据库获取java对应的类型
   * @param inputtype
   * @return
   */
  public static String getDbforJavaType(String inputtype){
	 String returnStr="";
	  switch(inputtype){
	  	case "int":
	  		returnStr="java.lang.Integer";
	  		break;
		case "varchar":
	  		returnStr="java.lang.String";
	  		break;
		case "char":
	  		returnStr="java.lang.String";
	  		break;
		case "text":
	  		returnStr="java.lang.String";
	  		break;
		case "longtext":
	  		returnStr="java.lang.String";
	  		break;
		case "longblob":
	  		returnStr="java.lang.String";
	  		break;
		case "integer":
	  		returnStr="java.lang.Integer";
	  		break;
		case "tinyint":
	  		returnStr="java.lang.Integer";
	  		break;
		case "bigint":
	  		returnStr="java.lang.Integer";
	  		break;
		case "float":
	  		returnStr="java.lang.Float";
	  		break;
		case "double":
	  		returnStr="java.lang.Double";
	  		break;
		case "decimal":
	  		returnStr="java.math.BigDecimal";
	  		break;
		case "date":
	  		returnStr="java.util.Date";
	  		break;
		case "datetime":
	  		returnStr="java.util.Date";
	  		break;
		case "timestamp":
	  		returnStr="java.util.Date";
	  		break;
		case "year":
	  		returnStr="java.util.Date";
	  		break;
	  	default:
	  		returnStr="java.lang.String";
	  		break;
	  }
	  return returnStr;
  }


	/**
	 * 下划线替换成下划线后首字母大写
	 * @param args
	 * @return
	 */
	public static String CapitalAsLowerCase(String args) {
		//变成小写
		args=args.toLowerCase();
		String[] str=args.split("_");
		for (String string : str) {
			int i=args.indexOf("_");
			if(i!=-1){
				String newstr=args.substring(i+1,i+2).toUpperCase();
				String newstr2=args.substring(i, i+2);
				args=args.replace(newstr2, newstr);
			}
		}
		return args;
	}
}
